clc
clear variables
dbstop if error
%close all
% 
% I1 = peaks(50);
% %I1 = imresize(I1, [ 100 120 ]);
% I2 = ImageTranslate(I1, 0.7, 0.5);
% 
% [ u v ] = RobustHornSchunk({ I1 I2} , 1, 0, 25, 1);
% u = u{1};
% v = v{1};
% 
% uMean = mean(u(:));
% vMean = mean(v(:));

[ images flowXGT flowYGT masks ] = YosemiteDataset;

im1 = imresize(images{1}, 0.25);
im2 = imresize(images{2}, 0.25);
flowXg = imresize(flowXGT{1}, 0.25);
flowYg = imresize(flowYGT{1}, 0.25);
[ flowX1 flowY1 ] = HornSchunk({ im1 im2 }, 1e-4, 0, 100, 1);
[ flowX2 flowY2 ] = RobustHornSchunk({ im1 im2} , 1e-4, 0, 100, 1);

u1 = flowX1{1};
v1 = flowY1{1};

u2 = flowX2{1};
v2 = flowY2{1};

ug = imresize(flowXGT{1}, 0.25);
vg = imresize(flowYGT{1}, 0.25);


% figure;
% subplot(1, 2, 1);
% hold on; title('Estimated Flow');
% imshow(MyFlowToColor(u, v, 0.1))
% subplot(1, 2, 2);
% hold on; title('Ground Truth Flow');
% imshow(MyFlowToColor(ug, vg, 0.1))

error  = AngularError(u1, v1, ug, vg);
meanError1 = mean(error(:))
error2  = AngularError(u2, v2, ug, vg);
meanError2 = mean(error2(:))